package com.qianyu.core.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qianyu.core.entity.bean.GameArea;
import com.qianyu.core.mapper.GameAreaMapper;
import com.qianyu.core.service.GameAreaService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class GameAreaServiceImpl extends ServiceImpl<GameAreaMapper, GameArea> implements GameAreaService {

    @Override
    public boolean saveGameArea(List<GameArea> areas,String appid) {
        if(validateArea(appid)){
            saveBatch(areas);
        }
        return true;
    }

    @Override
    public List<GameArea> listGameArea(String appid) {
        LambdaQueryWrapper<GameArea> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(GameArea::getAppid,appid);
        return list(wrapper);
    }

    private boolean validateArea(String appid){
        LambdaQueryWrapper<GameArea> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(GameArea::getAppid,appid);
        return ObjectUtil.isEmpty(baseMapper.selectList(wrapper));
    }
}
